var util = require('../../utils/util')
var api = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    task: {},
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('row', function (data) {
      //获取任务详情
      that.getTaskById(data.taskId)

    })

  },

  //获取任务详情
  getTaskById(taskId) {
    let that = this
    let dataup = {
      taskId: taskId

    }
    util.request(api.queryTaskDetail, JSON.stringify(dataup), 'POST').then(function (res) {
      console.log(res.data)
      if (res.code == '200') {
        that.closeModal();
        that.setData({
          task: res.data,
          imgListed: (res.data.hiddenReport.verifyImage || '').split(';').filter(item => item !== '')
        })

      } else {
        util.showErrorToast(res.message);
        that.closeModal();
      }

    }).catch((err) => {
      that.closeModal();
      console.log("登录远程服务器catch:" + err);
      //reject(err);
    });




  },

  //浏览核实照片
  ViewImageed(e) {
    wx.previewImage({
      urls: this.data.imgListed,
      current: e.currentTarget.dataset.url
    });
  },



  //进度条
  loadModal() {
    this.setData({
      loadModal: true
    })
  },
  closeModal() {
    this.setData({
      loadModal: false
    })
  },
  //保存提交
  save() {
  
    //提交上报数据
    let dataup = {
      taskId: this.data.task.taskId,
    };
    let that = this;
    that.loadModal();

    util.request(api.taskAssignment, JSON.stringify(dataup), 'POST').then(function (res) {
      console.log(res)
      if (res.code == '200') {
        that.closeModal();
        //刷新界面
        console.log("========")
        wx.navigateBack()

      } else {
        util.showErrorToast(res.message);
        that.closeModal();
      }

    }).catch((err) => {
      that.closeModal();
      console.log("登录远程服务器catch:" + err);
      //reject(err);
    });


  },


})